﻿


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Api;
using Controller;
using HBase;
using hCommand;
using Net.http;
using Persistence;
using Persistence.mySql;

namespace WebApi
{
    [FormAuthenticationFilter]

    [RoutePrefix("report")]
    public class ReportController : BaseApiController
    {
        IDoServer doServer = WMSDalFactray.getDal<IDoServer>();
        ICSDServer csdServer = WMSDalFactray.getDal<ICSDServer>();
        [HttpPost, Route("doStatPage")]
        public BaseResult doStatPage([FromBody] PDoStatDto dto) {//in out store stat
            var res=doServer.queryStat(dto); 
            return BaseResult.Ok(res);
        }


        [HttpPost, Route("iosList")]
        public BaseResult ios([FromBody]  PDoStatDto dto)
        {//in out store stat
           List<WhDoStat>  stats = doServer.getStat(dto);  
            List<InOutStoreData> res=new List<InOutStoreData>();
            Dictionary<String,InOutStoreData> dict = new Dictionary<String, InOutStoreData>();

            foreach (WhDoStat stat in stats) {
                InOutStoreData d = null;
                String key = stat.itemId + stat.createTime.ToString("yyyy-MM-dd");
                if (dict.ContainsKey(key)) {

                    d = dict[key];
                } else {
                    d = new InOutStoreData();
                    res.Add(d);
                    d.itemId = stat.itemId;
                    dict.Add(key, d);
                    d.createTime = stat.createTime;
                }
           
             
                d.termOut += stat.outCount;
                d.termIn+= stat.inCount;
                d.termEnd += stat.remain;
               
            } 
            return BaseResult.Ok(res);
        }
        [HttpGet, Route("statIos")]
        public BaseResult statIos( ) {  
            TaskPool.get<StatTask>().manual = true;
            return BaseResult.Ok("更新成功");
        }
        [HttpGet, Route("showIos")]
        public BaseResult showIos() { 
            return BaseResult.Ok(TaskPool.get<StatTask>().manual);
        }


        [HttpPost, Route("inert/{day}")]
        public BaseResult inert(int day) {//呆滞库存
             
            List<CoreStockDet> infoList = csdServer.inert(day);
            
            return BaseResult.Ok(infoList);
        }


        [HttpGet, Route("sync/{type}")]
        public BaseResult sync(int type) {//呆滞库存
           
            return BaseResult.Ok("同步命令下发成功");
        }

    }
}